package com.sz.biz.logistics.core.service.impl;

import com.sz.biz.common.constants.ModuleNames;
import com.sz.biz.logistics.core.entity.ServiceCargoTypeRel;
import com.sz.biz.logistics.core.service.ServiceCargoTypeRelService;
import com.sz.biz.logistics.core.dto.ServiceCargoDto;
import com.sz.common.base.constants.UserActions;
import com.sz.common.base.service.AbstractService;
import com.sz.common.core.service.PrincipalLogUtils;

import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Function: ServiceCargoTypeRelServiceImpl. <br>
 * Date: 2017年03月14日 14:27 <br>
 * Author: wentao.chang
 */
@Service
public class ServiceCargoTypeRelServiceImpl extends AbstractService implements ServiceCargoTypeRelService {

    /**
     * 新增
     *
     * @param list 新增的实体list
     * @return
     */
    @Override
    public void save(List<ServiceCargoTypeRel> list) {
        dao.batchInsert("ServiceCargoTypeRelMapper.insert", list);
      //保存操作日志
        Map<String, Object> dataBackup = new HashMap<>();
        dataBackup.put("ADD_SERVICE_CARGO_TYPEREL", list);
        PrincipalLogUtils.addOperationLog(ModuleNames.BIZ, ModuleNames.BIZ_SERVICE_CARGO_TYPE, UserActions.ADD, "新增服务货物类型", dataBackup);
    }

    @Override
    public List<ServiceCargoTypeRel> findByRefId(int refId) {
        return dao.findForList("ServiceCargoTypeRelMapper.findByRefId", refId, ServiceCargoTypeRel.class);
    }

    @Override
    public List<ServiceCargoDto> findCargosByServiceUid(String uid){
        return dao.findForList("ServiceCargoTypeRelMapper.findCargosByServiceUid", uid, ServiceCargoDto.class);
    }


    @Override
    public void deleteByServiceId(Integer serviceId) {
        dao.delete("ServiceCargoTypeRelMapper.deleteByServiceId", serviceId);
        //保存操作日志
        Map<String, Object> dataBackup = new HashMap<>();
        dataBackup.put("DELETE_SERVICE_CARGO_TYPEREL", serviceId);
        PrincipalLogUtils.addOperationLog(ModuleNames.BIZ,
                ModuleNames.BIZ_SERVICE_CARGO_TYPE,
                UserActions.DELETE, "根据id删除服务货物类型", dataBackup);
    }

    @Override
    protected String getMapperNamespace() {
        return "ServiceCargoTypeRelMapper";
    }
}
